package com.wanxi.controller;

import com.wanxi.model.LenghtModel;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;

/**
 * @Author:Doteon
 * @createDate:2023/2/28
 * @version: 1.0
 */
@Controller
@CrossOrigin(origins = "*")
public class LenghtController {
    @RequestMapping("/lenght")
    @ResponseBody
    @PreAuthorize("hasAuthority('subPermission') or hasAuthority('allPermission')or hasAuthority('unaccessible')")
    protected LenghtModel ss(LenghtModel model){
        switch (model.getOne()){
            case 0:
                zero(model);
                break;
            case 1:
                one(model);
                break;
            case 2:
                two(model);
                break;
            case 3:
                three(model);
                break;
            case 4:
                four(model);
                break;
            case 5:
                five(model);
                break;
            default:
                break;
        }
        return model;
    }


    private void five(LenghtModel model) {

        switch (model.getTwo()){
            case 0:
                model.setOutcome(model.getDigit().divide(BigDecimal.valueOf(1000000)));
                break;
            case 1:
                model.setOutcome(model.getDigit().divide(BigDecimal.valueOf(1000000000)));
                break;
            case 2:
                model.setOutcome(model.getDigit().divide(BigDecimal.valueOf(10000)));
                break;
            case 3:
                model.setOutcome(model.getDigit().divide(BigDecimal.valueOf(1000)));
                break;
            case 4:
                model.setOutcome(model.getDigit().divide(BigDecimal.valueOf(100000)));
                break;
            case 5:
                model.setOutcome(model.getDigit());
                break;
            default:
                break;
        }
    }

    private void four(LenghtModel model) {

        switch (model.getTwo()){
            case 0:
                model.setOutcome(model.getDigit().divide(BigDecimal.valueOf(10)));
                break;
            case 1:
                model.setOutcome(model.getDigit().divide(BigDecimal.valueOf(10000)));
                break;
            case 2:
                model.setOutcome(model.getDigit().multiply(BigDecimal.valueOf(10)));
                break;
            case 3:
                model.setOutcome(model.getDigit().multiply(BigDecimal.valueOf(100)));
                break;
            case 4:
                model.setOutcome(model.getDigit());
                break;
            case 5:
                model.setOutcome(model.getDigit().multiply(BigDecimal.valueOf(100000)));
                break;
            default:
                break;
        }
    }

    private void three(LenghtModel model) {

        switch (model.getTwo()){
            case 0:
                model.setOutcome(model.getDigit().divide(BigDecimal.valueOf(1000)));
                break;
            case 1:
                model.setOutcome(model.getDigit().divide(BigDecimal.valueOf(1000000)));
                break;
            case 2:
                model.setOutcome(model.getDigit().divide(BigDecimal.valueOf(10)));
                break;
            case 3:
                model.setOutcome(model.getDigit());
                break;
            case 4:
                model.setOutcome(model.getDigit().divide(BigDecimal.valueOf(100)));
                break;
            case 5:
                model.setOutcome(model.getDigit().multiply(BigDecimal.valueOf(1000)));
                break;
            default:
                break;
        }
    }

    private void two(LenghtModel model) {

        switch (model.getTwo()){
            case 0:
                model.setOutcome(model.getDigit().divide(BigDecimal.valueOf(100)));
                break;
            case 1:
                model.setOutcome(model.getDigit().divide(BigDecimal.valueOf(100000)));
                break;
            case 2:
                model.setOutcome(model.getDigit());
                break;
            case 3:
                model.setOutcome(model.getDigit().multiply(BigDecimal.valueOf(10)));
                break;
            case 4:
                model.setOutcome(model.getDigit().divide(BigDecimal.valueOf(10)));
                break;
            case 5:
                model.setOutcome(model.getDigit().multiply(BigDecimal.valueOf(10000)));
                break;
            default:
                break;
        }
    }

    private void one(LenghtModel model) {

        switch (model.getTwo()){
            case 0:
                model.setOutcome(model.getDigit().multiply(BigDecimal.valueOf(1000)));
                break;
            case 1:
                model.setOutcome(model.getDigit());
                break;
            case 2:
                model.setOutcome(model.getDigit().multiply(BigDecimal.valueOf(100000)));
                break;
            case 3:
                model.setOutcome(model.getDigit().multiply(BigDecimal.valueOf(1000000)));
                break;
            case 4:
                model.setOutcome(model.getDigit().multiply(BigDecimal.valueOf(10000)));
                break;
            case 5:
                model.setOutcome(model.getDigit().multiply(BigDecimal.valueOf(1000000000)));
                break;
            default:
                break;
        }
    }

    private void zero(LenghtModel model) {
        switch (model.getTwo()){
            case 0:
                model.setOutcome(model.getDigit());
                break;
            case 1:
                model.setOutcome(model.getDigit().divide(BigDecimal.valueOf(1000)));
                break;
            case 2:
                model.setOutcome(model.getDigit().multiply(BigDecimal.valueOf(100)));
                break;
            case 3:
                model.setOutcome(model.getDigit().multiply(BigDecimal.valueOf(1000)));
                break;
            case 4:
                model.setOutcome(model.getDigit().multiply(BigDecimal.valueOf(10)));
                break;
            case 5:
                model.setOutcome(model.getDigit().multiply(BigDecimal.valueOf(1000000)));
                break;
            default:
                break;
        }
    }


}
